package com.yuchen.bearrecord.repository;

import com.yuchen.bearrecord.entity.Prescription;
import com.yuchen.bearrecord.entity.User;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PrescriptionRepository extends JpaRepository<Prescription, Long> {
    @EntityGraph(attributePaths = "drugs")
    List<Prescription> findByUser(User user);

    Prescription findByPid(Long pid);

    List<Prescription> findByName(String name);

    @Transactional
    void deleteByPid(Long pid);

    @Transactional
    void deleteAllByUser(User user);
}
